<?php
require_once("../../inc/global.php");
require_once("function.php");
adminislogin();
if(strtolower($_SERVER['REQUEST_METHOD'])=='post'){
	$addSysName=$_POST["SysName"];
	$addSysTableName=$_POST["SysTableName"];
	if(!empty($addSysName)&&!empty($addSysTableName)){	
		$addSysTableName="sen_".$addSysTableName;
	
		$count=$db->getcount("select * from system where system3='{$addSysTableName}'");
		if($count==0){
			$addpathdir="../".$addSysTableName;
			$DefaultAddString="<?php\nrequire_once(\"../../inc/global.php\");\nrequire_once(\"../menusys/function.php\");\nadminislogin();\n\$MenuID=\$_GET[\"MenuID\"];\n\$html->includetop(\"\",\"style=\\\"width:98%\\\";\");\nYKT_Menu_ShowList(\$MenuID);\n\$html->includeend();\n?>";
			if(!file_exists($addpathdir)){
				mkdir($addpathdir,0700);  //创建文件夹
				$fp=@fopen($addpathdir."/index.php","w");  //创建index.php
				@fwrite($fp,$DefaultAddString);
				@fclose($fp);
			}
			$addpath="System/".$addSysTableName."/index.php";
			$addtablesql="CREATE TABLE ".$addSysTableName."(".$addSysTableName."0 int(11) NOT NULL auto_increment,".$addSysTableName."1 int(11) default 0,".$addSysTableName."2 varchar(100) default null,".$addSysTableName."3 varchar(100) default null,".$addSysTableName."4 int(11) default 0,PRIMARY KEY(".$addSysTableName."0)) ENGINE=MyISAM DEFAULT CHARSET=utf8;";	
			if($db->query($addtablesql)){  //创建数据库表
				if($db->query("insert into system(system1,system2,system3)values('$addSysName','$addpath','$addSysTableName')")){
					YKT_error('添加成功',$_SERVER['HTTP_REFERER']);
				}else{	
					YKT_error('添加失败',$_SERVER['HTTP_REFERER']);
				}
			}
		}else{
			YKT_error("添加失败，系统表: ".$addSysTableName." 已存在！！",$_SERVER['HTTP_REFERER']);
		}
	}
}
if(isset($_GET["act"])){
	$id=$_GET["id"];
	if(issql($id)){
		@$rows=$db->getoners("select * from system where system0={$id} limit 1");
		@$base->deldir("../".$rows[3]); //删除对应文件夹
		if($db->query("drop table {$rows[3]}")){
			if($db->query("delete from system where system0={$id} limit 1")){
				YKT_error('删除成功',$_SERVER['HTTP_REFERER']);
			}else{
				YKT_error('添加失败',$_SERVER['HTTP_REFERER']);
			}
		}
	}else{
		YKT_error('添加失败',$_SERVER['HTTP_REFERER']);
	}
}
$html->includetop("","style=\"width:98%\"");
$result=$db->query("select * from system");
$System->Systemlist($result);
$html->includemenusystemadd();
$html->includeend();

?>